#include "TackleBehaviour.h"

/*
 *	Urobi smykacku
 *
 *	@param power	sila smykacky
 */
void TackleBehaviour::Behave(const float power)
{
	commandGenerator->Tackle(power);
}


/*
 * Dokazeme smykackou vypichnut loptu? 
 *
 */
bool TackleBehaviour::CanTackleBall()
{
	// V tomto mode sa nemoze smykat
	if(world->state->GetPlayMode() != PM_PlayOn) return false;

	// Lopta musi byt v obdlzniku sirky (2*tackle_width) a vysky (tackle_dist + tackle_back_dist)
	// obdlznik je natoceny v smere natocenia hraca
	Vector player2ball = (world->ball->pos - world->me->pos);
	player2ball.SetAngle(player2ball.GetAngle() - world->me->GetAbsDir());

	// Hrac teda moze urobit smykacku ak:
	// je lopta vedla neho tackle_width a (za nim tackle_back_dist alebo pred nim tackle_dist)
	if(fabsf(player2ball.GetY()) >= world->params->server->tackle_width ||
	   player2ball.GetX() >= world->params->server->tackle_dist ||
	   player2ball.GetX() <= world->params->server->tackle_back_dist)
	return false;

	
	//DBGN("Tackle can be taken v(%.2f,%.2f) p(%.2f,%.2f;%.2f) b(%.2f,%.2f)",
	//	player2ball.GetX(), player2ball.GetY(),
	//	world->me->pos.GetX(), world->me->pos.GetY(), world->me->GetAbsDir().GetAbsDeg(),
	//	world->ball->pos.GetX(), world->ball->pos.GetY());

	return true;
}
